//
//  TF_LoadView.swift
//  TalkfunSDKDemo
//
//  Created by 邓盛明 on 2021/12/28.
//  Copyright © 2021 Talkfun. All rights reserved.
//

import UIKit

class TF_LoadView: UIView {

    var logoImageView:UIImageView!
    var courseNameLabel:UILabel!
    var tipsBtn:UIButton!
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(red: 56/255.0, green: 80/255.0, blue: 60/255.0, alpha: 1.0)
        self.logoImageView = UIImageView.init()
        self.addSubview(self.logoImageView)
        self.logoImageView.layer.masksToBounds  =  true
        
        self.courseNameLabel = UILabel.init()
        self.courseNameLabel.textAlignment = .center
        self.courseNameLabel.textColor = UIColor.white
        self.courseNameLabel.font = UIFont.systemFont(ofSize: 17)
        self.addSubview(self.courseNameLabel)
        
        self.tipsBtn = UIButton.init()
        self.tipsBtn.setTitle("即将进入...", for: .normal)
        self.tipsBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        self.tipsBtn.setTitleColor(UIColor(red: 162/255.0, green: 180/255.0, blue: 242/255.0, alpha: 1.0), for: .normal)
        self.addSubview(self.tipsBtn)
        self.tipsBtn.layer.borderWidth = 0.5;
        self.tipsBtn.isUserInteractionEnabled = false;
        self.tipsBtn.layer.borderColor = self.UIColorFromRGBHex(hexColor: 0x687fcd).cgColor
        self.logoImageView.layer.shadowColor = UIColor.gray.cgColor
        self.logoImageView.layer.shadowOffset = CGSize(width: 0, height: 0)
        self.logoImageView.layer.shadowOpacity = 0.5;
        self.logoImageView.backgroundColor = UIColor(red: 231/255.0, green: 231/255.0, blue: 231/255.0, alpha: 1.0)
        self.logoImageView.contentMode = .scaleAspectFit
    }
    
    @objc func UIColorFromRGBHex(hexColor:NSInteger) -> UIColor {

            let red = CGFloat((( hexColor & 0xFF0000 ) >> 16)) / 255.0
            let green = CGFloat((( hexColor & 0xFF00 ) >> 8)) / 255.0
            let blue = CGFloat((hexColor & 0xFF )) / 255.0

            let color = UIColor.init(red: red, green: green, blue: blue, alpha: 1.0)
            return color
        }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.logoImageView.frame = CGRect(x: (self.frame.size.width-120)/2.0, y: self.frame.size.height/3.0, width: 120, height: 120)
        self.courseNameLabel.frame = CGRect(x: 16, y: self.logoImageView.frame.maxY+25, width: self.frame.size.width-32, height: 21)
        self.tipsBtn.frame = CGRect(x: (self.frame.size.width-150)/2.0, y: self.courseNameLabel.frame.maxY+38, width: 150, height: 40)
        self.logoImageView.layer.cornerRadius = self.logoImageView.frame.width/2
    }
    
    @objc public func configLogo(logoUrl:String,courseName:String)  {
        DispatchQueue.main.async {
            
            self.logoImageView.sd_setImage(with: NSURL.init(string: logoUrl) as URL?, completed: nil)
            if courseName.isEmpty {
                self.courseNameLabel.text = ""
            } else {
                self.courseNameLabel.text = courseName
            }
        }
    }
    
   

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

}
